ensemble module

Module containing functions to interact with binary_c’s population ensemble using the binarycpython package

class binarycpython.utils.ensemble.BinarycDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)[source]

Bases: JSONDecoder

Custom decoder to transform the numbers that are strings to actual floats

decode(s)[source]

Entry point function for decoding

class binarycpython.utils.ensemble.BinarycEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

Encoding class function to attempt to convert things to strings.

default(o)[source]

Converting function. Well, could be more precise. look at the JSON module

binarycpython.utils.ensemble.binaryc_json_serializer(obj)[source]

Custom serialiser for binary_c to use when functions are present in the dictionary that we want to export.

Function objects will be turned into str representations of themselves

Parameters

obj (Any) – The object that might not be serialisable

Return type

Any

Returns

Either string representation of object if the object is a function, or the object itself

binarycpython.utils.ensemble.ensemble_compression(filename)[source]

Return the compression type of the ensemble file, based on its filename extension.

binarycpython.utils.ensemble.ensemble_file_type(filename)[source]

Returns the file type of an ensemble file.

binarycpython.utils.ensemble.ensemble_setting(ensemble, parameter_name)[source]

Function to get the setting of parameter_name in the given ensemble, or return the default value.

binarycpython.utils.ensemble.extract_ensemble_json_from_string(binary_c_output)[source]

Function to extract the ensemble_json information from a raw binary_c output string

Parameters

binary_c_output (str) – raw binary_c output string

Return type

dict

Returns

JSON dictionary with the parsed ENSEMBLE_JSON data

binarycpython.utils.ensemble.format_ensemble_results(ensemble_dictionary)[source]

Function to handle all the steps of formatting the ensemble output again.

Input:

ensemble_dictionary: dictionary containing all the ensemble results

binarycpython.utils.ensemble.handle_ensemble_string_to_json(raw_output)[source]

Function that deals with the raw output of the ensemble and creates a working JSON dictionary out of it.

Having this wrapper makes it easy to

Parameters

raw_output – raw output of the ensemble dump by binary_c

Returns

json.loads(raw_output, cls=BinarycDecoder)

binarycpython.utils.ensemble.load_ensemble(filename, convert_float_keys=True, select_keys=None, timing=False, flush=False, quiet=False)[source]

Function to load an ensemeble file, even if it is compressed, and return its contents to as a Python dictionary.

Parameters
  • convert_float_keys – if True, converts strings to floats.

  • select_keys – a list of keys to be selected from the ensemble.

binarycpython.utils.ensemble.new_grid_ensemble_results()[source]

Function to return a new grid_ensemble_results dict: this should be pre-filled by sub-dicts to prevent later errors.

binarycpython.utils.ensemble.open_ensemble(filename, encoding='utf-8')[source]

Function to open an ensemble at filename for reading and decompression if required.